package com.zlzlib.liblayoutmanager;

import android.content.Context;
import android.view.View;

/**
 * @Desc: 缩放重叠排列
 * @Copyright:
 * @DateTime: 2021/8/17 17:21
 * @Author zlz
 * @Version 1.0
 */
public class LayoutCarouselManager extends LayoutScaleManager {


    public LayoutCarouselManager(Context context) {
        this(context, 0);
    }

    public LayoutCarouselManager(Context context, int itemSpace) {
        this(context, itemSpace, HORIZONTAL);
    }

    public LayoutCarouselManager(Context context, int itemSpace, int orientation) {
        super(context, itemSpace, orientation);
        minScale = 0.5f;
        setEnableBringCenterToFront(true);
    }

    @Override
    protected void setItemViewProperty(View itemView, float targetOffset) {
        float scale = calculateScale(targetOffset + mSpaceMain);
        itemView.setScaleX(scale);
        itemView.setScaleY(scale);
    }

    @Override
    protected float setViewElevation(View itemView, float targetOffset) {
        return itemView.getScaleX() * 5;
    }

    private float calculateScale(float x) {
        float deltaX = Math.abs(x - (orientationUtils.getTotalSpace() - mDecoratedMeasurement) / 2f);
        return (minScale - 1) * deltaX / (orientationUtils.getTotalSpace() / 2f) + 1f;
    }

}
